﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Query
    {
        public Query(SqlConnection connection)
        {
            //查询数据库数据
            connection.Open();
            var sql = "SELECT * FROM [User]";
            SqlCommand command = new SqlCommand(sql, connection);
            var dr = command.ExecuteReader();
            Console.WriteLine("学号\t姓名\t性别\t年龄");
            while (dr.Read())
            {
                Console.WriteLine($"{dr[0]}\t{dr[1]}\t{dr[2]}\t{dr[3]}");
            }
            connection.Close();
        }
    }
}
